<?php

use yii\helpers\Html;
//use yii\bootstrap\ActiveForm;
use kartik\form\ActiveForm;
use kartik\touchspin\TouchSpin;


/* @var $this yii\web\View */
/* @var $model app\modules\Product\models\ProductFlight */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Product Flights'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
?>
<div class="product-flight-update">

   <h2 class="page-header"><?= Html::encode($this->title) ?>
        <p class="pull-right">
            <?= Html::a(Yii::t('app', 'Index'), ['index','product_id'=>$model->product_id], ['class' => 'btn btn-danger']) ?>
        </p>
    </h2>

    <?php $form = ActiveForm::begin(['type'=>ActiveForm::TYPE_HORIZONTAL,'formConfig' => ['labelSpan' => 2,'deviceSize' => ActiveForm::SIZE_SMALL],'fullSpan'=>9]); ?>

    <?= $form->field($model, 'id')->hiddenInput()->label(false) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'num',[
            'addon' => ['prepend' => 
                    ['content'=>Html::button('出库', ['class'=>'btn btn-primary','data-toggle'=>'modal','data-target'=>'#minusModal']),'asButton' => true ],
                    'append' => 
                    ['content'=>Html::button('入库', ['class'=>'btn btn-primary','data-toggle'=>'modal','data-target'=>'#plusModal']),'asButton' => true ]       
            ],
            'horizontalCssClasses'=>['label' => 'col-sm-2','wrapper' => 'col-sm-2'],
])->textInput(['maxlength' => true,'disabled'=>'disabled','class'=>'form-control text-center']) ?>

    <?= $form->field($model, 'price')->textInput(['maxlength' => true,]) ?>

    <?= $form->field($model, 'remark')->textarea(['rows'=>1]) ?> 

    <?= $form->field($model, 'status')->radioList(\Yii::$app->params['status'],['inline'=>true]) ?>



    <div class="form-group text-center">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<!-- modal -->
<div class="modal fade" id="minusModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">出库存</h4>
      </div>
      <div class="modal-body">
           <div class="row form-horizontal">
             <div class="form-group">   
                <label class="control-label col-sm-3">减少数量</label>
                <div class="col-sm-7">
                    <input class="form-control" id="delnum" type="text" value="">
                </div>
              </div> 
              <div class="form-group text-center"> 
               <button type="button" id="delButton" class="btn btn-default btn-primary" data-dismiss="modal">确定</button>  
              </div>  
          </div>  
      </div>
      
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- modal -->
<div class="modal fade" id="plusModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">入库存</h4>
      </div>
      <div class="modal-body">
         <div class="row form-horizontal">
             <div class="form-group">   
                <label class="control-label col-sm-3">增加数量</label>
                <div class="col-sm-7">
                    <input class="form-control" type="text" id="addnum" value="">
                </div>
              </div>
              <div class="form-group text-center"> 
               <button type="button" id="addButton" class="btn btn-default btn-primary" data-dismiss="modal">确定</button>  
              </div> 
          </div>  
      </div>
    
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">  
    $("#addButton").click(function(){
        var flight_id = $("#productflight-id").val();
        var num = $("#addnum").val();
        $.get("/product/product-extra/flight-upnum",{'flight_id': flight_id,'num':num,'action':1}, function(data){
            if(data.code == 1){
                $("#productflight-num").val(data.num);
                //alert('操作成功');
            }else{
                 //alert('操作失败');
            }  
        });
    });
     $("#delButton").click(function(){
        var flight_id = $("#productflight-id").val();
        var num = $("#delnum").val();
        $.get("/product/product-extra/flight-upnum",{'flight_id': flight_id,'num':num,'action':0}, function(data){
            if(data.code == 1){
                $("#productflight-num").val(data.num);
                //alert('操作成功');   
            }else{
                //alert('操作失败');
            }  
        });
    });
    

</script>
<?php app\components\JsBlock::end() ?>
